﻿using System;
using System.Windows.Media;
using System.Windows.Data;
using BizControl.Library.BusinessObjects;
using BizControl.Library.BusinessObjects.Marks;

namespace BizControl.Presentation.Infrastructure.Converters
{
  public class MarkStateToBrushConverter : IValueConverter
  {
    public MarkStateToBrushConverter()
    {
      OverdueTaskBrush = Brushes.Red;
      CompletedTaskBrush = Brushes.Green;
      NotStartedTaskBrush = Brushes.Blue;
    }

    public Brush OverdueTaskBrush { get; set; }
    public Brush CompletedTaskBrush { get; set; }
    public Brush NotStartedTaskBrush { get; set; }

    #region IValueConverter Members

    public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      Brush brush = Brushes.Transparent;
      if (value is MarkState)
      {
        if (((MarkState)value).HasFlag(MarkState.Completed)) brush = CompletedTaskBrush;
        else
        {
          if (((MarkState)value).HasFlag(MarkState.Overdue)) brush = OverdueTaskBrush;
          else if (((MarkState)value).HasFlag(MarkState.NotStarted)) brush = NotStartedTaskBrush;
          else brush = Brushes.Transparent;
        }
      }
      return brush;
    }

    public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      return null;
    }

    #endregion
  }
}